{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "$$\n",
    "E_{(w,b)} = \\sum_{i=1}^m(y_i-wx_i-b)^2 = (y_1-wx_1-b)^2 + \\cdots + (y_m-wx_m-b)^2\n",
    "$$\n",
    "\n",
    "现在对$w$和$b$分别求偏导\n",
    "\n",
    "$$\n",
    "\\begin{equation}\n",
    "\\begin{aligned}\n",
    "\\frac{\\partial E_{(w,b)}}{\\partial w} &= 2(y_1-wx_1-b)(-x_1) + \\cdots + 2(y_m-wx_m-b)(-x_m) \\\\\n",
    "&= 2(-y_1x_1+wx_1^2+bx_1) + \\cdots + 2(-y_mx_m+wx_m^2+bx_m) \\\\\n",
    "&= 2(w\\sum_{i=1}^mx_i^2 - \\sum_{i=1}^m(y_i-b)x_i)\n",
    "\\end{aligned}\n",
    "\\end{equation}\n",
    "$$\n",
    "\n",
    "$$\n",
    "\\begin{equation}\n",
    "\\begin{aligned}\n",
    "\\frac{\\partial E_{(w,b)}}{\\partial b} &= 2(y_1-wx_1-b)(-1) + \\cdots + 2(y_m-wx_m-b)(-1) \\\\\n",
    "&= 2(wx_1+b-y_1) + \\cdots + 2(wx_m+b-y_m) \\\\\n",
    "&= 2(mb-\\sum_{i=1}^m(y_i-wx_i))\n",
    "\\end{aligned}\n",
    "\\end{equation}\n",
    "$$\n",
    "\n",
    "令$\\frac{\\partial E_{(w,b)}}{\\partial w}$和$\\frac{\\partial E_{(w,b)}}{\\partial b}$分别为$0$, 就可以求解二元一次方程，得到$w$和$b$的值。\n",
    "\n",
    "即:\n",
    "\n",
    "$$\n",
    "2(w\\sum_{i=1}^mx_i^2 - \\sum_{i=1}^m(y_i-b)x_i) = 0\n",
    "$$"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
